package com.wc.alorithm_luogu.P1781;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2023/5/13 15:31
 * @description https://www.luogu.com.cn/problem/P1781
 * 宇宙总统
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = Integer.parseInt(sc.next());

        // 记录答案字符串
        String ans;
        // 记录答案序列
        int ansIdx;

        String compareStr;

        ansIdx = 1;
        ans = sc.next();
        for (int i = 2; i <= n; i++) {
            compareStr = sc.next();
            compareStr = compareStr(compareStr, ans);
            if (!compareStr.equals(ans)) {
                ans = compareStr;
                ansIdx = i;
            }
        }

        System.out.println(ansIdx);
        System.out.println(ans);
    }

    public static String compareStr(String s1, String s2) {
        // 先比较长度
        if (s1.length() > s2.length()) {
            return s1;
        } else if (s1.length() < s2.length()) {
            return s2;
        }
        char[] sCh1 = s1.toCharArray();
        char[] sCh2 = s2.toCharArray();

        // 然后从大到小比较
        for (int i = 0; i < sCh1.length; ++i) {
            if (sCh1[i] > sCh2[i]) {
                return s1;
            } else if (sCh1[i] < sCh2[i]) {
                return s2;
            }
        }
        return s1;
    }
}
